package org.me.SendSMS;

import org.me.SendSMS.utli.GlobalVariable;

import com.google.android.apps.analytics.GoogleAnalyticsTracker;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;


public class SelectTimeActivity extends Activity implements OnClickListener{
	
	Context mContext;
	String hours	="0";
	String minute 	= "0";
	Button btnSet,btnCancel;
	Button btnCongHours, btnTruHours,btnCongMinute,btnTruMinute;
	EditText editHours,editMinute;
	private GoogleAnalyticsTracker tracker;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_LEFT_ICON);
		 tracker = GoogleAnalyticsTracker.getInstance();
	     // Start the tracker in manual dispatch mode...
	    tracker.startNewSession("UA-35081259-1", getApplication());
		setContentView(R.layout.set_time);
		getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon_time);
		


		mContext = this;
		
		editHours		= (EditText)findViewById(R.id.editHour);
		editMinute		= (EditText)findViewById(R.id.editMinute);
		
		
		
		if(GlobalVariable.HOURS_CURRENT<10)
		{
			hours = "0"+String.valueOf(GlobalVariable.HOURS_CURRENT);
		}
		else
		{
			hours = String.valueOf(GlobalVariable.HOURS_CURRENT);
		}
		if(GlobalVariable.MINUTE_CURRENT<10)
		{
			minute = "0"+String.valueOf(GlobalVariable.MINUTE_CURRENT);
		}
		else
		{
			minute = String.valueOf(GlobalVariable.MINUTE_CURRENT);
		}
		
		
		
		
		
		editHours.setText(hours);
		editMinute.setText(minute);
		
		
		
		btnSet 			= (Button)findViewById(R.id.Set);
		btnCancel		= (Button)findViewById(R.id.Cancel);
		
		btnCongHours	= (Button)findViewById(R.id.btnCongHours);
		btnTruHours		= (Button)findViewById(R.id.btnTruHours);
		
		btnCongMinute	= (Button)findViewById(R.id.btnCongMinute);
		btnTruMinute	= (Button)findViewById(R.id.btnTruMinute);
		
		btnSet.setOnClickListener(this);
		btnCancel.setOnClickListener(this);
		
		btnCongHours.setOnClickListener(this);
		btnTruHours.setOnClickListener(this);
		
		btnCongMinute.setOnClickListener(this);
		btnTruMinute.setOnClickListener(this);
		
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		switch (v.getId()) {
		case R.id.Cancel:
			
			finish();
			break;
		case R.id.btnCongHours:
			GlobalVariable.HOURS_CURRENT = Integer.parseInt(editHours.getText().toString());
			GlobalVariable.HOURS_CURRENT ++;
			
			if(GlobalVariable.HOURS_CURRENT>23)
			{
				GlobalVariable.HOURS_CURRENT = 0;
			}
			if(GlobalVariable.HOURS_CURRENT<10)
			{
				editHours.setText("0" + String.valueOf(GlobalVariable.HOURS_CURRENT));
			}
			else
			{
				editHours.setText(String.valueOf(GlobalVariable.HOURS_CURRENT));
			}
			break;
		case R.id.btnTruHours:
			GlobalVariable.HOURS_CURRENT = Integer.parseInt(editHours.getText().toString());
			GlobalVariable.HOURS_CURRENT --;
			if(GlobalVariable.HOURS_CURRENT<=0)
			{
				GlobalVariable.HOURS_CURRENT = 24;
			}
			if(GlobalVariable.HOURS_CURRENT<10)
			{
				editHours.setText("0" + String.valueOf(GlobalVariable.HOURS_CURRENT));
			}
			else
			{
				editHours.setText(String.valueOf(GlobalVariable.HOURS_CURRENT));
			}
			break;
		case R.id.btnCongMinute:
			GlobalVariable.MINUTE_CURRENT = Integer.parseInt(editMinute.getText().toString());
			GlobalVariable.MINUTE_CURRENT ++;
			if(GlobalVariable.MINUTE_CURRENT>59)
			{
				GlobalVariable.MINUTE_CURRENT = 0;
			}
			
			if(GlobalVariable.MINUTE_CURRENT<10)
			{
				editMinute.setText("0" + String.valueOf(GlobalVariable.MINUTE_CURRENT));
			}
			else
			{
				editMinute.setText(String.valueOf(GlobalVariable.MINUTE_CURRENT));
			}
			
			break;
		case R.id.btnTruMinute:
			GlobalVariable.MINUTE_CURRENT = Integer.parseInt(editMinute.getText().toString());
			GlobalVariable.MINUTE_CURRENT --;
			if(GlobalVariable.MINUTE_CURRENT<=0)
			{
				GlobalVariable.MINUTE_CURRENT = 59;
			}
			if(GlobalVariable.MINUTE_CURRENT<10)
			{
				editMinute.setText("0" + String.valueOf(GlobalVariable.MINUTE_CURRENT));
			}
			else
			{
				editMinute.setText(String.valueOf(GlobalVariable.MINUTE_CURRENT));
			}
			break;
		case R.id.Set:
			GlobalVariable.HOURS = Integer.parseInt(editHours.getText().toString());
			GlobalVariable.MINUTE = Integer.parseInt(editMinute.getText().toString());
			GlobalVariable.STARTTIME = true;
			finish();
			


		default:
			break;
		}
		
	}

}
